package com.miyake.loveviewweb.client.community;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.miyake.loveviewweb.client.dialog.DialogHandler;
import com.miyake.loveviewweb.client.dialog.IDialogPanel;
import com.miyake.loveviewweb.shared.model.GroupModel;

public class GroupSearchPanel extends Composite implements IDialogPanel {
    private DialogHandler handler;
    private GroupModel selectedGroup;
    
    public GroupSearchPanel() {
        VerticalPanel panel = new VerticalPanel();
        panel.setWidth("100%");
        initWidget(panel);
        
        GroupListTable list = new GroupListTable(IGroupList.GroupListType.AllGroup, new GroupListHandler() {
            
            public void onSelect(GroupModel groupModel) {
                if (handler != null) {
                    setSelectedGroup(groupModel);
                    handler.onOK();
                }
            }
            
        }) {

            @Override
            protected String getButtonCaption() {
                return "Join";
            }
            
        };
        list.setWidth("600px");
        panel.add(list);
        list.update();
    }

    public void setDialogHandler(DialogHandler handler) {
        this.handler = handler;
    }

    public Composite getComposite() {
        return this;
    }

    /**
     * @return the selectedGroup
     */
    public GroupModel getSelectedGroup() {
        return selectedGroup;
    }

    /**
     * @param selectedGroup the selectedGroup to set
     */
    private void setSelectedGroup(GroupModel selectedGroup) {
        this.selectedGroup = selectedGroup;
    }
}
